package com.example.shop_2302

import android.os.Bundle
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.base.mvvm.BaseViewActivity
import com.example.shop_2302.databinding.ActivityWebViewBinding

@Route(path = "/app/WebViewActivity")
class WebViewActivity : BaseViewActivity<ActivityWebViewBinding>() {
    //由外部传一个参数url
    @JvmField //将字段设为公开的
    @Autowired  //当两边参数名称一致时可省略name
    var url = ""
    override fun initView() {
        ARouter.getInstance().inject(this)//将数据注入到对应的activity或者fragment中
        binding.wv.loadUrl(url)
        binding.wv.webViewClient = WebViewClient()//在app内部显示
        val webChromeClient = object :WebChromeClient(){
            override fun onProgressChanged(view: WebView?, newProgress: Int) {
                super.onProgressChanged(view, newProgress)
                if(newProgress==100){
                    binding.pb.isVisible = false//进度条消失
                }
                binding.pb.progress = newProgress
            }
        }
        binding.wv.webChromeClient = webChromeClient
        binding.wv.settings.javaScriptEnabled = true//可点击页面上的控件
    }

    override fun initData() {

    }

    override fun getLayout(): Int  = R.layout.activity_web_view

}